grammar SampleAST;

options {
  language = Java;
  output=AST;
  ASTLabelType=CommonTree;
  
}
tokens {
  NEGATION;
}

@header {
  package ast.gen;
}

@lexer::header {
  package ast.gen;
} 


evaluator 
  : assigment* expression EOF! 
  ; 

assigment
  : IDENT ':='^ expression ';'!
  ;
  
term 
  :IDENT   
  |'('! expression ')'! 
  |INTEGER
  ;

negation
  : '-' -> NEGATION
  ;

unary 
  : ('+'^ | negation^ )* term
  ;
  
 mult
  :unary(('*'^ |'/'^ |'mod'^ ) unary )*
  ;
 
expression 
  :mult  (('+'^ |'-'^ ) mult )*
  ;

INTEGER : '0'..'9'+;
IDENT : ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9' )*; 
WS: (' '|'\t'|'\n'|'\r'|'\f')+ {$channel = HIDDEN;};